#!/bin/bash
clear

if [[ "$EUID" -ne 0 ]]; then
    echo "Script need to be run as root!" && exit 1
fi

apt-get -qq update
DEBIAN_FRONTEND=noninteractive apt-get -y -qq install dropbear

echo 'NO_START=0
DROPBEAR_PORT=440
DROPBEAR_EXTRA_ARGS="-p 441 -p 442"
DROPBEAR_BANNER="/etc/issue.net"
DROPBEAR_RSAKEY="/etc/dropbear/dropbear_rsa_host_key"
DROPBEAR_DSSKEY="/etc/dropbear/dropbear_dss_host_key"
DROPBEAR_ECDSAKEY="/etc/dropbear/dropbear_ecdsa_host_key"
DROPBEAR_RECEIVE_WINDOW=65536' > /etc/default/dropbear
systemctl restart dropbear

function dropbear_detail() {
    local isActive=$(systemctl is-active dropbear.service)
    local isEnable=$(systemctl is-enabled dropbear.service)
    local unitID=$(systemctl show dropbear.service -p Id)
    local unitName=$(systemctl show dropbear.service -p Names)
    local unitDesc=$(systemctl show dropbear.service -p Description)
    local portList="440(stunnel) 441(default) 442(extra)"
    echo "";
    echo "Dropbear service detail"
    echo "ID: $unitID"
    echo "Names: $unitName"
    echo "Description: $unitDesc"
    echo "Listening: $portList";
    if [[ "$isActive" -eq 0 ]]; then
        echo " Dropbear service is: Active"
    fi
    if [[ "$isEnable" -eq 0 ]]; then
        echo " Dropbear service is: Enabled"
    fi
}
dropbear_detail
sleep 5
